package com.byit.config;

import com.byit.filter.XssFilter;
import com.byit.jwt.lifecycle.JwtSessionLifecycleAspect;
import com.byit.jwt.lifecycle.JwtSessionOutLifecycleAspect;
import com.byit.utils.SpringUtil;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author marker
 **/
@Configuration
public class CustomConfig {


    /**
     * Spring utils 工具类
     */
    @Bean
    public SpringUtil beanSpringUtils() {
        return new SpringUtil();
    }


    /**
     * JwtSession 登录 AOP 操作
     *
     * @return
     */
    @Bean
    public JwtSessionLifecycleAspect jwtSessionLifecycleAspect() {
        return new JwtSessionLifecycleAspect();
    }


    /**
     * JwtSession 注销 AOP 操作
     *
     * @return
     */
    @Bean
    public JwtSessionOutLifecycleAspect jwtSessionOutLifecycleAspect() {
        return new JwtSessionOutLifecycleAspect();
    }


    public FilterRegistrationBean FilterRegistration1() {
        FilterRegistrationBean registration = new FilterRegistrationBean();
        registration.setFilter(new XssFilter());//添加过滤器
        registration.addUrlPatterns("/app/*");//设置过滤路径，/*所有路径
        registration.setName("XssFilter");//设置优先级
        registration.setOrder(1);//设置优先级
        return registration;
    }


}
